<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.TimeZone"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="eBrain.beans.Item"%>
<%@page import="eBrain.beans.Bid"%>
<jsp:useBean id="dataManager" scope="application"
  class="eBrain.model.DataManager"/>
 <%String base = (String)application.getAttribute("base"); %>
   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.Calendar"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="/eBrain/css/eshop.css" type="text/css"/>
</head>
<body>
<jsp:include page="TopMenu.jsp" flush="true"/>
<jsp:include page="LeftMenu.jsp" flush="true"/>

 <div class="content">
 
      <table>
        <tr>
          <th>Name</th>
          <th>Start Date</th>
          <th>End Date</th>
          <th>Time Left</th>
          <th>Bid</th>
          </tr>
<%
        ArrayList items = dataManager.getItems();
        Iterator iterator = items.iterator();
        while (iterator.hasNext()) {
          Item item = (Item)iterator.next();
         if(item.getEnd().after(new Date(System.currentTimeMillis()))){
  %>
          <tr>
            <td><a href="<%=base%>?action=openItem&id=<%=item.getId()%>"><%=item.getName()%></a></td>
            <td><%=item.getStart()%></td>
            <td><%=item.getEnd()%></td>
            
            <td><%		TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
            			Calendar c = Calendar.getInstance();
            			c.setTimeInMillis(item.getEnd().getTime());
            			Calendar c2 = Calendar.getInstance();
            			long a = item.getEnd().getTime()-c2.getTimeInMillis();
            		  	SimpleDateFormat sdfTime = new SimpleDateFormat(" dd' Days 'HH:mm:ss");
     					out.print(sdfTime.format(a));
     					
            		
             %>
            <td><%Bid bid = dataManager.getMaxBidForItem(item.getId());
            		if(bid.isEmpty()){
            		out.println(item.getStartBid());
            		}
            		else{
            		out.println(bid.getBidValue());
            		}
            		%></td>
            </tr>
<%
          }}
  %>
        </table>
      </div>




</body>
</html>